/**
 * Project: complex.algorithm
 * 
 * File Created at 2011-8-30
 * $Id$
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.complex.algorithm;

/**
 * 插入排序
 * @author ymkyve
 *
 */
public class InsertSort extends Sort{
    
    public static void main(String[] args) {
        InsertSort sort = new InsertSort();
        sort.sort();
        sort.print();
    }
    
    @Override
    public void sort(){
        int temp;
        for(int i=1;i<arr.length;i++){
            for(int j=i;(j>0) && (arr[j]<arr[j-1]);j--){
                //swap
                temp =arr[j];
                arr[j] = arr[j-1];
                arr[j-1]=temp;
            }
        }
    }
}
